<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        ul{
           width:300px;
           height:50px;
           display: flex;
           background-color: aquamarine;
           margin:0 auto;
        }
        li{
            list-style: none;
            height:50px;
            width:100px;
            line-height:50px;
            text-align: center;
        }
        li.active{
            background-color:pink;
        }
        .content{
            height:200px;
            width:300px;
            margin:0 auto;
        }
        .content div{
            height:200px;
            width:300px;
            background-color:pink;
            line-height: 200px;
            text-align: center;
            display: none;
        }
        .content div.active{
            display: block;
        }
    </style>
</head>
<body>
    <ul>
        <li class="active">电视</li>
        <li>音乐</li>
        <li>舞蹈</li>
    </ul>
    <div class="content">
        <div class="active">电视内容</div>
        <div>音乐内容</div>
        <div>舞蹈内容</div>
    </div>

    <script>
        var lis=document.getElementsByTagName("li");
        var divs=document.querySelectorAll(".content div");
        
        for(var i=0;i<lis.length;i++){
            lis[i].index=i;
            //console.dir(lis[i]);
            lis[i].onclick=function(){
                //当点击执行函数的时候，循环结束了，这时候的i为3
                //console.log(i);//3

                //不确定上个样式在哪个元素上，所以全部删除class,给点击的那个添加class
                for(var n=0;n<lis.length;n++){
                    lis[n].className="";
                    divs[n].className="";
                }
                //给点击的那个添加class
                lis[this.index].className="active"; 
                divs[this.index].className="active";
            }
        }
        
    </script>
</body>
</html>